package org.cxn.tools.json;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by chenxiangning on 2015/8/9.
 */
public class Test {
    public static void main(String[] args) {
        String json = "[{\"CityId\":18,\"CityName\":\"西安\",\"ProvinceId\":27,\"CityOrder\":1},{\"CityId\":53,\"CityName\":\"广州\",\"ProvinceId\":27,\"CityOrder\":1}]";
        String two = "{\"cityId\":53,\"cityName\":\"广州\",\"provinceId\":27,\"cityOrder\":1,\"date\":\"2015-08-09 20:27:20\"}";
        List list = JsonUtil.jsonToList(json);
        Map map = JsonUtil.jsonToMap(two);

        City city = (City) JsonUtil.jsonToBean(two,City.class);

        System.out.println(city);

        System.out.println(JsonUtil.getJsonValue(two, "cityName"));

        System.out.println(JsonUtil.objectToJson(city));

        System.out.println(JsonUtil.objectToJsonDateSerializer(city, "yyyy-MM-dd"));

        City city1 = JsonUtil.jsonToBeanDateSerializer(two,City.class,"yyyy-MM-dd");

        System.out.println(city1);
    }

    public static class City{
        String cityId;
        String cityName;
        String provinceId;
        String cityOrder;
        Date date;

        public Date getDate() {
            return date;
        }

        public void setDate(Date date) {
            this.date = date;
        }

        public String getCityId() {
            return cityId;
        }

        public void setCityId(String cityId) {
            this.cityId = cityId;
        }

        public String getCityName() {
            return cityName;
        }

        public void setCityName(String cityName) {
            this.cityName = cityName;
        }

        public String getProvinceId() {
            return provinceId;
        }

        public void setProvinceId(String provinceId) {
            this.provinceId = provinceId;
        }

        public String getCityOrder() {
            return cityOrder;
        }

        public void setCityOrder(String cityOrder) {
            this.cityOrder = cityOrder;
        }

        @Override
        public String toString() {
            return "City{" +
                    "cityId='" + cityId + '\'' +
                    ", cityName='" + cityName + '\'' +
                    ", provinceId='" + provinceId + '\'' +
                    ", cityOrder='" + cityOrder + '\'' +
                    '}';
        }
    }
}
